import React from "react";
import { hashHistory } from 'react-router';
import { Checkbox } from 'antd';
import DelOrderMutation from "../mutation/DelOrderMutation";
import Relay from "react-relay";
export default class OrderPurch_Item extends React.Component{
    constructor(props){
        super(props)
        this.goodtypeobj={'1':'成衣','2':'辅料','3':'面料','4':'印染','5':'纱线'}
        this.state={
            checked:false
        }
    }

    componentWillMount(){

    }

    addorderstatus(status){
        if(status==2){
            return <div className="order_list_saleandre_from_td_doitcontext_div">{'签订'}</div>
        }else if(status==3){
            return <div className="order_list_saleandre_from_td_doitcontext_div">{'收货'}</div>
        }else if(status ==4){
            return '交易完成'
        }else if(status==1){
            return '暂时无人接单'
        } else if(status==0){
            return <div className="order_list_saleandre_from_td_doitcontext_div">{'删除'}</div>
        }
    }

    dosomebystatus(status,oid,oty){
        switch (status){
            case 0:
                Relay.Store.commitUpdate(
                    new DelOrderMutation({
                        orderId : oid
                    }),
                    {
                        onFailure: () => {

                        },
                        onSuccess: (response) => {
                            this.props.reloadList();
                        }
                    }
                )

                return;
            case 1:
                return;
            case 2:
                this.jumpDetil(oty,oid)
                return;
            case 3:
                // hashHistory.push({pathname:'/receiveGoods/',state:{'oid':oid}})
                hashHistory.push({pathname:'/receiveGoodsItem/',state:{'oid':oid}})
                return;
            case 4:
                return;

        }

    }

    jumpDetil(oty,oid){
        switch (oty){
            case 0:

                return;
            case 1:
                hashHistory.push('/orderdetailgms/'+oid);
                // hashHistory.push({pathname:'/orderdetailgms/',state:{'oid':oid}})
                return;
            case 2:
                hashHistory.push('/orderdetailraw/'+oid);
                // hashHistory.push({pathname:'/orderdetailraw/',state:{'oid':oid}})
                return;
            case 3:
                hashHistory.push('/orderdetailcloth/'+oid);
                // hashHistory.push({pathname:'/orderdetailcloth/',state:{'oid':oid}})
                return;
            case 4:
                hashHistory.push('/orderdetailprint/'+oid);
                // hashHistory.push({pathname:'/orderdetailprint/',state:{'oid':oid}})
                return;
            case 5:
                hashHistory.push('/orderdetailyarn/'+oid);
                // hashHistory.push({pathname:'/orderdetailprint/',state:{'oid':oid}})
                return;

        }

    }

    jupmGoodsItem(oid,odt) {
        hashHistory.push({pathname: '/receiveGoodsDetil/', state: {'oid': oid}})
        // hashHistory.push({pathname:'/receiveGoodsItem/',state:{'oid':oid,'odt':odt}})
    }

    jumptree(oid){
        hashHistory.push({pathname:'/ordertree/',state:{'oid':oid}})
    }

    jumpOrderProgress(oid){
        hashHistory.push({pathname:'/OrderProgress/',query:{'oid':oid}})
    }

    _onChangeBox(e){
        let checked = e.target.checked;
        this.props._onChangeBoxCallBack(this.props.index,this.props.context.oid,this.props.context.account,checked,this.props.context.status,this.props.context.orderType);
        this.setState({
            checked:checked
        });
    }

    _onChangeBoxTrue(){
        this.setState({
            checked:true
        });
    }
    _onChangeBoxFalse(){
        this.setState({
            checked:false
        });
    }
    jumptree(oid){
        hashHistory.push({pathname:'/ordertree/',state:{'oid':oid}})
    }

    render(){
        let context = this.props.context;
        return (
            <thead>
            <tr className={this.props.index%2==0?"order_list_saleandre_from_trchange":"order_list_saleandre_from_tr"}>
                <td className="order_orderpurch_item_from_td order_orderpurch_item_from_td_check"><Checkbox onChange={this._onChangeBox.bind(this)}
                                                                                                            checked={this.state.checked}/></td>
                {
                    context.orderType ==1?
                        <td className="order_orderpurch_item_from_td order_orderpurch_item_from_td_oid_otyp1" onClick={this.jumptree.bind(this,context.oid)}>{context.oid}</td>
                        :
                        <td className="order_orderpurch_item_from_td order_orderpurch_item_from_td_oid">{context.oid}</td>
                }

                <td className="order_orderpurch_item_from_td order_orderpurch_item_from_td_partb">{context.partBName}</td>
                <td className="order_orderpurch_item_from_td order_orderpurch_item_from_td_product">{this.goodtypeobj[context.orderType]}</td>
                <td className="order_orderpurch_item_from_td order_orderpurch_item_from_td_count">{Number(context.orderGoodsNum).toFixed(3)}</td>
                <td className="order_orderpurch_item_from_td order_orderpurch_item_from_td_count">{Number(context.orderGoodsNum-context.remainOrderGoodsNum).toFixed(3)}</td>
                <td className="order_orderpurch_item_from_td order_orderpurch_item_from_td_money">{context.account/100}</td>
                <td className="order_orderpurch_item_from_td order_orderpurch_item_from_td_money">{context.payAccount/100}</td>
                <td className="order_orderpurch_item_from_td order_list_saleandre_from_td_doitcontext" onClick={this.dosomebystatus.bind(this,context.status,context.oid,context.orderType)}>{
                    this.addorderstatus(context.status)
                }</td>
                <td className="order_orderpurch_item_from_td order_orderpurch_item_from_td_endcontext" onClick={this.jupmGoodsItem.bind(this,context.oid,context.orderType)}>查看</td>
                <td className="order_orderpurch_item_from_td order_orderpurch_item_from_td_endcontext" onClick={this.jumpOrderProgress.bind(this,context.oid)}>查看</td>
                <td className="order_orderpurch_item_from_td order_orderpurch_item_from_td_endcontext" onClick={this.jumpDetil.bind(this,context.orderType,context.oid)}>查看</td>
            </tr>
            </thead>
        )
    }
}
